/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.webhomesites.principal;

import br.com.webhomesites.configuracao.utils.Conexao;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;

/**
 *
 * @author Webhome
 */
public class EmissaoRelatorios {
DecimalFormat df = new DecimalFormat("###,###,###.00");
    DecimalFormat df2 = new DecimalFormat("###,###,###.0");
    DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
    
    public void imprimirContrato(Integer codlocacao, int modelo) {
        try {
            
            Map parameterMap = new HashMap();
            
            String arquivo = null;
            if (modelo == 1) {
                arquivo = System.getProperty("user.dir") + "/ContratoLocacaoV1.jasper";
            } else if (modelo == 2) {
                arquivo = System.getProperty("user.dir") + "/ContratoLocacaoV2.jasper";
            } else if (modelo == 3) {
                arquivo = System.getProperty("user.dir") + "/ContratoLocacaoV3.jasper";
            } else if (modelo == 4) {
                arquivo = System.getProperty("user.dir") + "/ContratoLocacaoV4.jasper";
            }

            parameterMap.put("PARLOC", codlocacao);

            JasperPrint jp = JasperFillManager.fillReport(arquivo, parameterMap, Conexao.conectar());
            JasperViewer.viewReport(jp, false);

        } catch (Exception ex) {
            Logger.getLogger(EmissaoRelatorios.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void imprimirReciboDevolucaoParcial(Integer codlocacao) {
        try {

            Map parameterMap = new HashMap();

            String arquivo = System.getProperty("user.dir") + "/ReciboDevolucao.jasper";

            parameterMap.put("CODIGO", codlocacao);

            JasperPrint jp = JasperFillManager.fillReport(arquivo, parameterMap, Conexao.conectar());
            JasperViewer.viewReport(jp, false);

        } catch (Exception ex) {
            Logger.getLogger(EmissaoRelatorios.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void imprimirRelatorioLocacao() {
        try {

            Map parameterMap = new HashMap();

            String arquivo = System.getProperty("user.dir") + "/Locacao.jasper";

            parameterMap.put("PAR_EMRPESA", 1);
            
            JasperPrint jp = JasperFillManager.fillReport(arquivo, parameterMap, Conexao.conectar());
            JasperViewer.viewReport(jp, false);

        } catch (Exception ex) {
            Logger.getLogger(EmissaoRelatorios.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void locacoesPorCliente(Integer codcliente, Date dataLocacao, Date dataFinalLocacao) {
        try {
        
            Map parameterMap = new HashMap();
        
            String arquivo = System.getProperty("user.dir") + "/LocacoesPorCliente.jasper";

            parameterMap.put("DATALOCACAO", dataLocacao);
            parameterMap.put("DATAFINALLOCACAO", dataFinalLocacao);
            parameterMap.put("CODCLIENTE", codcliente);
        
            JasperPrint jp = JasperFillManager.fillReport(arquivo, parameterMap, Conexao.conectar());
            JasperViewer.viewReport(jp, false);

        } catch (Exception ex) {
            Logger.getLogger(EmissaoRelatorios.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
